"nodejs";
let yamlFn = require("./yamlFn");
let 返回牙叔教程 = require("./返回牙叔教程");
let config = require("./config");
/* -------------------------------------------------------------------------- */
let qa = yamlFn.read();
/* -------------------------------------------------------------------------- */
async function handleMessage(data) {
  console.log("data = " + JSON.stringify(data));
  let { groupId, groupName, message } = data;
  let 限制群名列表 = config.限制群名列表;
  // let 限制群名列表 = ["私人订制3"];
  if (限制群名列表.indexOf(groupName) < 0) {
    return false;
  } else {
    console.log("是指定群: " + groupName);
  }
  let raw_message = message;
  // 从语雀 牙叔教程 找教程
  if (raw_message.indexOf("#") > -1) {
    if (raw_message.length >= 3) {
      let all = false;
      if (raw_message.indexOf("all") > -1) {
        all = true;
      }
      let 牙叔教程msg = await 返回牙叔教程(raw_message.replace("#", "").replace("all", ""), all);
      if (!牙叔教程msg) {
        return false;
      }
      let data = {
        groupName: groupName,
        groupId: groupId,
        message: 牙叔教程msg,
      };
      console.log("将要发送的消息: data = " + JSON.stringify(data));
      return data;
    }
  }
  let public = qa.public;
  if (public[raw_message]) {
    console.log("属于公共关键词");
    console.log("向群组发送消息: " + groupName + " : " + public[raw_message]);
    let data = {
      groupName: groupName,
      groupId: groupId,
      message: public[raw_message],
    };
    return data;
  } else {
    console.log("不属于公共关键词");
  }
  let group_name = groupName;
  if (qa[group_name]) {
    console.log("有群组: " + group_name);
    if (qa[group_name][raw_message]) {
      console.log("发现关键词 : " + raw_message);
      console.log("向群组发送消息: " + groupName + " : " + qa[group_name][raw_message]);
      let data = {
        groupName: groupName,
        groupId: groupId,
        message: qa[group_name][raw_message],
      };
      return data;
    } else {
      console.log("没有发现关键词 : " + raw_message);
    }
  } else {
    console.log("没有群组: " + group_name);
  }
  return false;
}
module.exports = handleMessage;
